/*
 * Stylesheet.java
 *
 * Created on 19 aprile 2004, 21.54
 */

package net.ermannofranco.xml.style;

import net.ermannofranco.xml.Doc;
import net.ermannofranco.xml.Namespace;
import net.ermannofranco.xml.Static;
import net.ermannofranco.xml.schema.SchemaException;

/**
 * 
 * @author ermanno (ermanno.franco@gmail.com)
 */
public class Stylesheet extends Doc {

	private static final long serialVersionUID = -2097551326009311251L;
	private static final String DEFAULTXSLTURI = "http://www.w3.org/1999/XSL/Transform";
	private static String DEFAULTID = "xsl";
	private static String DEFAULT_EXT = "." + DEFAULTID;
	private static final Namespace DEFAULT_NS = new Namespace(DEFAULTID,
			DEFAULTXSLTURI);

	private final String schemaPrefix;
	private final double DEFAULTXSLVERSION = 1.0;

	/** Creates a new instance of Stylesheet */
	public Stylesheet() {
		this(DEFAULT_NS, null);
	}

	/**
	 * @param creator
	 */
	public Stylesheet(Class<?> creator) {
		this(DEFAULT_NS, creator);
	}

	/**
	 * @param schemaPrefix
	 * @param creator
	 */
	public Stylesheet(String schemaPrefix, Class<?> creator) {
		this(new Namespace(schemaPrefix, DEFAULTXSLTURI), creator);
	}

	/**
	 * @param schemaPrefix
	 * @param schemaURI
	 * @param creator
	 */
	public Stylesheet(Namespace ns, Class<?> creator) {
		super("stylesheet", ns, creator);
		this.schemaPrefix = ns.getPrefix();
		extension = DEFAULT_EXT;
		if (Static.isMinimalStr(schemaPrefix)) {
			throw new SchemaException("prefisso di namespace xsl obbligatorio");
		}
		setEncoding("UTF-8");
		omitStandaloneAttr();
		setXSLVersion(DEFAULTXSLVERSION);

	}

	/**
	 * @param version
	 * @return autoref
	 */
	public Stylesheet setXSLVersion(double version) {
		addAttr("version", "" + version);
		return this;
	}

	/**
	 * @param matchExpr
	 * @return
	 */
	public Template addTemplate(String matchExpr) {
		Template t;
		add(t = new Template(1, this).setMatch(matchExpr));
		return t;
	}

	/**
	 * @return
	 */
	public String getDefaultExtension() {
		return "." + DEFAULTID;
	}

}
